package com.yujin.topic;
import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;
import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory;
/**
 * JMS消费者:消息订阅者1
 * @author Administrator
 */
public class JMSConsumer {
	
	private static final String USERNAME = ActiveMQConnection.DEFAULT_USER;
	private static final String PASSWORD = ActiveMQConnection.DEFAULT_PASSWORD;
	private static final String BROKERURL = ActiveMQConnection.DEFAULT_BROKER_URL;
	
	public static void main(String[] args) {
		
		ConnectionFactory factory = null;
		Connection conn = null;
		Session session = null;
		Destination destination = null;
		MessageConsumer messageConsumer = null; //消息消费者
		factory = new ActiveMQConnectionFactory(USERNAME, PASSWORD, BROKERURL);
		try {
			conn = factory.createConnection();
			conn.start();  //启动连接
			session = conn.createSession(Boolean.FALSE, Session.AUTO_ACKNOWLEDGE);
			destination = session.createTopic("firstTopic");
			messageConsumer = session.createConsumer(destination);
			
			messageConsumer.setMessageListener(new Listener()); //注册消息监听
			
		}catch(JMSException e){
			e.printStackTrace();
		}finally{
		}
	}
}
